<?php
class App_Scenictype
{
	public static  function getTypeListWithCityCn()
	{
		$query=DB::select('s.id','s.name','c.cityName','c.countryName')
		->from(array('mod_scenic_type','s'))
		->join(array('mod_city','c'))
		->on('s.cityId','=','c.id')
		->execute()->as_array();
		$ret=array();
		foreach ($query as $type)
		{
            if(strpos($type['cityName'], '|')!==FALSE)
            {
              $type['cityName'] = explode('|',$type['cityName']);
              $type['cityName']=trim($type['cityName'][0]);
            }
            if(strpos($type['countryName'], '|')!==FALSE)
            {
              $type['countryName'] = explode('|',$type['countryName']);
              $type['countryName']=trim($type['countryName'][0]);
            }
			$ret[$type['id']]=$type['countryName'].'|'.$type['cityName'].'|'.$type['name'];
		}
		return $ret;
	}
	
    public static  function getTypeListByCityId($cityId=NULL)
    {
        $query=DB::select('id','name')->from('mod_scenic_type');
        if(!empty($cityId))
        {
          $query=$query->where('cityId','=',$cityId);
        }
        $query=$query->execute()->as_array();
        $list=array();
        foreach($query as $v)
        {
          $list[$v['id']]=$v['name'];
        }
        return $list;
    }

    public static  function getTypeNameById($id)
	{
		$query=DB::select('name')
		->from('mod_scenic_type')
		->limit(1)
		->where('id','=',$id)
		->execute()->as_array();
		return $query[0]['name'];
	}
}
